Minimum Length Of String After Deleting Similar Ends - Leetcode 1750 - Python